package com.th.apicenter.rta.service;

import com.google.gson.Gson;
import com.th.apicenter.config.ApplicationProperties;
import com.th.apicenter.rta.dto.JDRTADTO;
import com.th.apicenter.rta.vo.JDRTAVO;
import com.th.apicenter.tools.OkhttpClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@Slf4j
public class JDRTAService {

    @Autowired
    private ApplicationProperties applicationProperties;

    public void JDRTA() {
        JDRTADTO jdrtadto = new JDRTADTO();
        jdrtadto.setRequestId("2003091938554448962");
        jdrtadto.setMediaCode("testmedia");
        jdrtadto.setIdType("oaid_orgnl");
        jdrtadto.setIdMd5Value("b80490b3a151e0eb58d0b31971a4d684");
        String jdrtadtoGson = new Gson().toJson(jdrtadto);
        try {
            String rtaResult = OkhttpClient.sendPostRequest(applicationProperties.getJd().getRTAUrl(), jdrtadtoGson);
            Gson gson = new Gson();
            JDRTAVO jdrtavo = gson.fromJson(rtaResult, JDRTAVO.class);
            log.info("京东rta返回的数据：{}", jdrtavo);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 接收京东回传
     * @param cbId
     * @param event_type
     */
    public void cb(String cbId, String event_type) {

    }

}
